package lc20240621;

public class FindMinNum {
    public static int findMin(int[] nums) {
        int left=0;
        int right= nums.length-1;
        int min=nums[left];
        //这里不能是<=，因为小于等于会出现越界情况导致最后出现的结果索引比结果索引大1
        while (left<right){
            int mid=left+(right-left)/2;
            if (nums[mid]<nums[right]){
                right=mid;
            }else{
                left=mid+1;
            }
        }
        return nums[left];
    }

    public static void main(String[] args) {
        int[] nums = {4, 5, 6, 7, 0, 1, 2};
        System.out.println(findMin(nums));
    }
}
